home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0082_Spell a Number.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  3KB  |  63 lines

  1. {
  2. From: MIKE COPELAND
  3. Subj: Spell a Number
  4. ---------------------------------------------------------------------------
  5. >>       I'm in the process of writing a Checkbook program for my Job
  6. >>       and I was wondering if anyone out there has a routine to
  7. >>     convert a check amount written in numerical to text.  Here's an
  8. >>     example of what I need. Input Variable :  142.50
  9. >>    Needed Output  : One Hundred Forty Two 50/100--------------------
  10.  
  11.    What you're looking for is "spell-a-number", and here's a program
  12. which does it.  Note that this one operates only on integer-type data,
  13. and you'll have to modify it for the decimal part - but that's the
  14. easiest task...  If you have questions, just post them here.
  15. }
  16. program Spell_A_Number;                     { MRCopeland 901105 }
  17. USES CRT;
  18. const C_ONES : array[1..9] of string[6] = ('one ','two ','three ','four ',
  19.                               'five ','six ','seven ','eight ','nine ');
  20.       C_TEEN : array[0..9] of string[10] = ('ten ','eleven ','twelve ',
  21.                               'thirteen ','fourteen ','fifteen ',
  22.                               'sixteen ','seventeen ','eighteen',
  23.                               'nineteen');
  24.       C_TENS : array[2..9] of string[8] = ('twenty ','thirty ','forty ',
  25.                               'fifty ','sixty ','seventy ','eighty ',
  26.                               'ninety ');
  27. var   I,J  : LongInt;                             { global data }
  28.  
  29. procedure HUNS (N : LongInt);           { process a 0-999 value }
  30. var P : integer;                          { local work variable }
  31. begin
  32.   P := N div 100; N := N mod 100;                { any 100-900? }
  33.   if P > 0 then
  34.     write (C_ONES[P],'hundred ');
  35.   P := N div 10;  N := N mod 10;                        { 10-90 }
  36.   if P > 1 then                                         { 20-90 }
  37.     write (C_TENS[P])
  38.   else
  39.     if P = 1 then                                       { 10-19 }
  40.       write (C_TEEN[N]);
  41.   if (P <> 1) and (N > 0) then        { remainder of 1-9, 20-99 }
  42.     write (C_ONES[N]);
  43. end;  { HUNS }
  44.  
  45. begin  { MAIN LINE }
  46.   ClrScr;
  47.   write ('Enter a value> '); readln (I);
  48.   if I > 0 then
  49.     begin
  50.       J := I div 1000000; I := I mod 1000000;
  51.       if J > 0 then                          { process millions }
  52.         begin
  53.           HUNS (J); write ('million ')
  54.         end;
  55.       J := I div 1000; I := I mod 1000;
  56.       if J > 0 then                         { process thousands }
  57.         begin
  58.           HUNS (J); write ('thousand ')
  59.         end;
  60.       HUNS (I)                        { process 0-999 remainder }
  61.     end                                                    { if }
  62. end.
  63.